home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Tele / T / Terminal 1.7.cpt / Terminal.doc < prev    next >
Text File  |  1989-11-06  |  39KB  |  1,025 lines

  1. ===========================================================================
  2. "Terminal"                 A Serial Communication Program For The Macintosh
  3. ===========================================================================
  4.  
  5.                         Version 1.7 (November 1989)
  6.  
  7.  
  8. ___________________________________________________________________________
  9. INTRODUCTION
  10.  
  11.  
  12. "Terminal" is a serial communication program for the Macintosh computer.
  13. Features are:
  14.  
  15. * Fast display. No characters are lost, even at 9600 Baud with text capture
  16. to disk enabled. (For most commercial programs this only holds for short
  17. term until the serial input buffer is full.)
  18.  
  19. * Capture buffer, so that the last 32768 (default, can be configured)
  20. characters are always available in the scrolling terminal window. The
  21. buffer can be saved as TEXT file to disk. Very fast scrolling to move
  22. around in the buffer.
  23.  
  24. * Text capture to disk, so that everything received or transmitted is saved
  25. automatically to a TEXT file on disk.
  26.  
  27. * Send TEXT files from disk. Wait for prompt string before sending line,
  28. delay after each line, delay after each character, XON/XOFF, CTS or no
  29. handshake.
  30.  
  31. * Binary file transfer using X-Modem protocol (checksum, CRC or 1K
  32. options), Y-Modem batch or CompuServe-B protocol (up- and download).
  33. Automatic recognition of MacBinary (I and II) file format. The effective
  34. speed of X-Modem file transfers is faster than most commercial programs.
  35. Useful if transferring files between two direct connected computers at fast
  36. speed.
  37.  
  38. * Built-in C interpreter with a rich set of intrinsic functions to execute
  39. scripts from TEXT files. Scripts can be as simple as modem setup, dial or
  40. auto-logon, but can also be used to program a complete BBS.
  41.  
  42. * Very compact program. Only uses 57K on disk and can run in a 128K
  43. partition under MultiFinder.
  44.  
  45. * Complete non-modal program (even during file transfers), and runs in
  46. background under MultiFinder.
  47.  
  48. * The program is free.
  49.  
  50. * Source code is available (written in THINK C 3.02).
  51.  
  52.  
  53. ___________________________________________________________________________
  54. CONFIGURATION
  55.  
  56.  
  57. "Terminal" was developed (in THINK C 3.02) and tested on a Macintosh Plus
  58. and on a Macintosh IIcx with System 6.03. The program is MultiFinder aware
  59. and can work in the background.
  60.  
  61. 128K ROMs (or newer) are required, so "Terminal" will not run on "old"
  62. Macs. Please use the most recent system software. The so-called "RAM serial
  63. driver" is not included as a resource, it should be in the ROM. The
  64. "ScriptUtil" trap is is used to map the "Option" key into the control key,
  65. and this trap was not available on older Systems.
  66.  
  67.  
  68. ___________________________________________________________________________
  69. FILES AND FOLDERS
  70.  
  71.  
  72. * "Terminal" the application, can be anywhere on your disk.
  73.  
  74. * "Terminal Settings" is created by "Terminal" in the System folder to
  75. store the options selected. If this file is not found when "Terminal"
  76. starts up default options will be used.
  77.  
  78. * "Terminal Scripts" is a folder that should be created in the same folder
  79. as the "Terminal" application. All scripts (a script is a TEXT file with a
  80. suffix of ".s") in this folder will be included in the "Scripts" menu for
  81. easy execution. If this folder does not exist, all scripts in the same
  82. folder as the "Terminal" application will be included in the "Scripts"
  83. menu.
  84.  
  85. * The "Terminal options" menu can be used to select a start-up script, that
  86. will be automatically executed when the application is started. This script
  87. can be anywhere on the disk. By default there is no start-up script.
  88.  
  89. * For use with Y-Modem batch and CompuServe-B file transfers a folder must
  90. exist on the disk where all downloads and uploads using these protocols
  91. will look for and store files. This folder can be selected by using the
  92. "File transfer options" menu option. The default folder is the same as the
  93. folder containing the "Terminal" application. This folder is also the
  94. default folder used by script file commands.
  95.  
  96.  
  97. ___________________________________________________________________________
  98. THE TERMINAL WINDOW
  99.  
  100.  
  101. There is a fixed size window with 24 lines and 80 columns (default values,
  102. can be configured). The window can be moved anywhere on the screen. A
  103. vertical scroll bar allows fast moving around in the last 32768 (default
  104. value, can be configured) characters received. If a new character is
  105. received the text automatically scrolls to the end. Everything received is
  106. displayed in the terminal window, even if the window is not the frontmost
  107. or if the application was switched out under MultiFinder.
  108.  
  109. The name of the window will be "Terminal" if no script is executing,
  110. otherwise the window name will be the same as the name of the script file.
  111. To cancel a running script select it again under the corresponding menu
  112. item.
  113.  
  114. If the terminal window is frontmost everything typed on the keyboard is
  115. transmitted. If the local-echo option is selected it is also echoed to the
  116. window. To send control characters the "Option" key can be used if there is
  117. no "Control" key. The "Command" key can be used as usual to select menu
  118. commands.
  119.  
  120. After file transfers a statistics message is displayed in the top area of
  121. the window showing how much bytes were transferred in how much time. This
  122. area is also used to display error messages. If a message is displayed a
  123. button appears to the left of it. Clicking this button will erase the
  124. message and the button. Note that such a message is not a modal dialog but
  125. will stay as long as there is no new message or until it is cleared.
  126. Meanwhile the program continues its normal operation.
  127.  
  128. During file transfers a dialog window (this is a non-modal window, not a
  129. modal dialog box, and can be moved around or deselected, and all menu
  130. commands are still available while this window is up) is displayed. This
  131. dialog window shows the progress of the file transfer and has a "Cancel"
  132. button. By clicking in this "Cancel" button the file transfer can be
  133. aborted. The file transfer can also be canceled by selecting the
  134. corresponding menu item.
  135.  
  136. Characters received in terminal mode are filtered using the following
  137. criteria (this is what I consider basic TTY emulation):
  138.  
  139. * All bytes received will get their most significant bit stripped to make 7
  140. bit ASCII characters.
  141.  
  142. * A "CR" character (carriage return, ASCII 13) will move the cursor to the
  143. first position in the next line.
  144.  
  145. * A "Backspace" character will erase the last character received and move
  146. the cursor one position to the left, but will never move to the previous
  147. line. The code to be recognized as "Backspace" can be chosen (see "Options
  148. menu"). If TEXT file capture is on, all characters are saved as received in
  149. the file including the "Backspace" characters.
  150.  
  151. * A "TAB" character (ASCII 9) will be accepted (and saved if TEXT file
  152. capture is on) but displayed as a space character.
  153.  
  154. * Two consecutive "CAN" (control-X, ASCII 24) are recognized as a signal
  155. to abort text file sends or X/Y-Modem file transfers.
  156.  
  157. * All other control characters are ignored and only characters with ASCII
  158. codes higher then 32 and lower than 126 are accepted (printable
  159. characters).
  160.  
  161. * If lines longer than 80 characters are received a "CR" will be inserted
  162. automatically after every 80 characters, and this "CR" will also be saved
  163. to disk if TEXT capture is on.
  164.  
  165.  
  166. ___________________________________________________________________________
  167. THE "FILE" MENU
  168.  
  169.  
  170. SAVE CAPTURE BUFFER
  171.  
  172. A standard file dialog is presented (if the capture buffer is not empty)
  173. allowing to save the contents of the capture buffer to disk as a TEXT file.
  174. The TEXT file creator can be changed using the "Text capture option" item
  175. in the "OPTIONS" menu.
  176.  
  177.  
  178. TEXT CAPTURE
  179.  
  180. A standard file dialog is presented allowing to create the TEXT file where
  181. all further input or output will be saved. The TEXT file creator can be
  182. changed using the "Text capture option" item in the "OPTIONS" menu. The
  183. menu text will change to outlined and expanded, so that when selected again
  184. the capture file will be closed. The file is also automatically closed when
  185. quitting the program.
  186.  
  187.  
  188. TEXT SEND
  189.  
  190. A standard file dialog is presented to select a TEXT file. The file
  191. contents is sent using the options that can be selected in the "TEXT file
  192. transfer options..." item of the "Options" menu. The menu text will change
  193. to outlined and expanded, so that when selected again the transmission will
  194. be canceled. If two control-X characters are received the transmission is
  195. also canceled.
  196.  
  197.  
  198. FILE RECEIVE
  199.  
  200. If Y-Modem batch is active (see "Binary File Transfer Options" menu), the
  201. file transfer starts immediatly. During a batch session more than one file
  202. my be received. All files received are stored in the folder selected by the
  203. "Binary File Transfer Options" dialog. If MacBinary file format is enabled,
  204. the file name used will be the name from the MacBinary header if this name
  205. does not yet exist, otherwise the name from the Y-Modem header (block 0)
  206. will be used, and if a file with this name exists it is deleted first. If
  207. MacBinary is disabled the file name from the Y-Modem header (block 0) is
  208. used, and if a file with this name exists it is deleted first.
  209.  
  210. If no batch is choosen a standard file dialog is presented to create a file
  211. to be used for binary file receive using X-Modem protocol. The X-Modem
  212. protocol file receive session is started. If MacBinary file format is
  213. enabled, the file name used will be the name from the MacBinary header if
  214. this name does not yet exist, otherwise the first chosen name will be used.
  215.  
  216. Note that for CompuServe-B protocol file transfers there is no need for
  217. this menu option as the transfers will be initiated by the host and the
  218. host will prompt you for the file name on your computer.
  219.  
  220.  
  221. FILE TRANSMIT
  222.  
  223. A standard file dialog is presented to select the binary file to transmit
  224. using X-Modem or Y-Modem protocol. If the MacBinary file format is enabled
  225. the file is sent in MacBinary II format. In Y-Modem batch only one file can
  226. be send in a session.
  227.  
  228. Note that for CompuServe-B protocol file transfers there is no need for
  229. this menu option as the transfers will be initiated by the host and the
  230. host will prompt you for the file name on your computer.
  231.  
  232.  
  233. MAKE MACBINARY FILE
  234.  
  235. Use this utility option to create a MacBinary II file from any other file
  236. on your disk. Normally this need not to be used, because the FILE TRANSMIT
  237. menu command will create the MacBinary II file on the fly while
  238. transmitting.
  239.  
  240.  
  241. EXTRACT FROM MACBINARY FILE
  242.  
  243. Use this utility option to extract a file from a MacBinary I or MacBinary
  244. II file on your disk. This is useful if you have forgotten to enable
  245. automatic MacBinary recognition and you have already downloaded a file.
  246.  
  247.  
  248. QUIT
  249.  
  250. To quit and return to the Finder use this option or click in the close box
  251. of the terminal window.
  252.  
  253.  
  254. ___________________________________________________________________________
  255. THE "EDIT" MENU
  256.  
  257.  
  258. Most items are only there for desk accessories. Only the following is used:
  259.  
  260.  
  261. CLEAR CAPTURE BUFFER
  262.  
  263. This will clear the capture buffer and the terminal window.
  264.  
  265.  
  266. DEBLOCK SEND
  267.  
  268. This kills any outstanding serial write request. It might be useful if the
  269. program has received an XOFF, but never got the XON.
  270.  
  271.  
  272. ___________________________________________________________________________
  273. THE "OPTIONS" MENU
  274.  
  275.  
  276. The options selected in the following dialogs are saved in a file in the
  277. system folder, so that they are again available when the program is started
  278. at a later time (the file name is "Terminal Settings"). If no options file
  279. is found in the system folder when the program is started, default values
  280. will be used.
  281.  
  282.  
  283. COMMUNICATION
  284.  
  285. Baud rate: 300 to 56700 Baud.
  286. Data bits: 7 or 8.
  287. Stop bits: 1 or 2.
  288. Parity: even, odd or none.
  289. Port: Modem or printer.
  290.  
  291. Don't drop DTR when quitting: useful if you don't want the modem to hang-up
  292. when you quit the program.
  293.  
  294. Note: During binary file transfers the data bits are set to 8 bits. When
  295. the transfer is finished the original value is restored.
  296.  
  297.  
  298. TEXT FILE SEND
  299.  
  300. Wait for prompt before sending next line: If this option is checked the
  301. program will wait for the prompt string (this can be more than one
  302. character) before sending the next line while sending TEXT files.
  303.  
  304. Delay after each line sent: If this option is checked the program waits for
  305. the specified number of ticks (1/60 second) before sending the next line
  306. while sending TEXT files.
  307.  
  308. Delay after each character sent: If this option is checked the program
  309. waits the specified number of ticks (1/60 second) before sending the next
  310. line while sending TEXT files.
  311.  
  312. Handshake: Possible choices are XON/XOFF, CTS (useful if sending a TEXT
  313. file to a printer, or a terminal node controller for packet radio using
  314. hardware handshake) or no handshake.
  315.  
  316.  
  317. BINARY FILE TRANSFER
  318.  
  319. MacBinary: use and recognize MacBinary file format in file transfers (Note
  320. that pure TEXT files are never sent as MacBinary).
  321.  
  322. CIS-B: recognize and use CompuServe-B protocol for file transfers.
  323.  
  324. Path for up- and downloads: folder name used for CIS-B up- and downloads
  325. (because the host will only prompt for the file name on your computer but
  326. not the path name) and for Y-Modem batch file downloads (where only the
  327. file name is in the header block).
  328.  
  329. X-Modem or Y-Modem:
  330. * CRC        If not checked "classic" X-Modem with simple checksum and 128
  331.              Byte blocks will be used. The "1K" options are disabled.
  332.              If checked CRC error checking will be used and the "1K" options
  333.              are enabled.
  334. * 1K off     128 Byte blocks are used.
  335.      aut     128 or 1024 Byte blocks are used automatically and where
  336.              appropriate. During the initial handshaking phase the single
  337.              character "C" is used. This is the "official" way of doing it.
  338.      CK      1024 Byte blocks are used if during the initial handshaking
  339.              phase the two character sequence "CK" is used (this is used by
  340.              Red Ryder 10.3 and perhaps others).
  341. * batch off  No batch protocol is used, i.e. this is X-Modem.
  342.         Y    "Official" Y-Modem batch protocol is used.
  343.         RR   A variant of the Y-Modem batch protocol is used where there is
  344.              no new handshaking phase after the header block (block 0) has
  345.              been sent (this is used by Red Ryder 10.3 and perhaps others).
  346. * timeout    Select the value 5, 10, 15 or 20 seconds.
  347.  
  348.  
  349. TERMINAL
  350.  
  351. Echo: local (display keyboard characters), remote (retransmit received
  352. characters).
  353.  
  354. Display and capture: if checked the capture window and buffer are active,
  355. else nothing is displayed nor captured.
  356.  
  357. AutoLF: If this option is checked a linefeed character will be send after
  358. each carriage return character.
  359.  
  360. Start-up script: Any script can be selected to be executed automatically
  361. when the "Terminal" application is started.
  362.  
  363.  
  364. OTHER
  365.  
  366. Text capture file creator: file creator for TEXT files used for saving the
  367. capture buffer or by the "Text file capture" option. So if you double-
  368. click on these files your favorite text editor program is automatically
  369. called.
  370.  
  371. File type and creator for non-MacBinary files: if automatic MacBinary file
  372. format recognition is not enabled, or if the file received is not a valid
  373. MacBinary file, this type (default is 'TEXT') and creator are used for the
  374. new file.
  375.  
  376. Code for "backspace" key: ASCII code send by pressing the "Backspace" key,
  377. and also the ASCII code recognized as "Backspace" code while receiving.
  378.  
  379. Code for "`' key: ASCII code send by pressing the "`" key. This can be used
  380. to make an "ESC" key (ASCII 27) on keyboards that don't have an "ESC" key.
  381.  
  382. Note that for sending control characters (e.g. cntl-C) the "Option" key can
  383. be used on the keyboard if there is no control key.
  384.  
  385.  
  386. ___________________________________________________________________________
  387. THE "SCRIPTS" MENU
  388.  
  389.  
  390. A script is a TEXT file containing a program written in "Terminal" script
  391. language, which is a subset of the C language. Scripts are interpreted by
  392. "Terminal", there is no compilation step involved. The easiest way to
  393. maintain scripts is to use a desk accessory TEXT editor. If you use a word
  394. processor, you must save the script files as pure TEXT, not in the native
  395. format of the word processor.
  396.  
  397. The first item in this menu can be used to select any script file on your
  398. disk using a standard file dialog box. Only TEXT files with a suffix of
  399. ".s" are considered to be scripts.
  400.  
  401. The other items depend on what "Terminal" found in it's folder when it was
  402. started. If a folder "Terminal Scripts" exists in the application folder,
  403. all script files found there are included in the menu. If no such folder
  404. exists all script files found in the application folder are listed in the
  405. menu. Selecting a script in the menu will start it. The menu item name
  406. changes to outlined and expanded. To cancel a running script simply select
  407. it's menu item again. If a script is running the terminal window's name is
  408. set to the name of the executing script.
  409.  
  410. Only one script at a time can be executing. Any script can be selected to
  411. execute automatically when "Terminal" is started by using the "Terminal
  412. Options" menu.
  413.  
  414.  
  415. ___________________________________________________________________________
  416. THE SCRIPT LANGUAGE
  417.  
  418.  
  419. The script language interpreted by "Terminal" is a subset of C with many
  420. specialized intrinsic (built-in) functions. Please read a C reference book
  421. to learn the C syntax, or see the enclosed script examples to get a feeling
  422. of the language. I will not write a book about programming in C here, only
  423. tell you the essentials.
  424.  
  425.  
  426. PROGRAM
  427.  
  428. A program is recognized as a script if it is in a TEXT file, and if the
  429. file name ends in ".s". Spaces, tabs and carriage return characters are
  430. considered to be white space. No identifier and no keyword can be separated
  431. by white space. A program consists of: comments, global variable
  432. definitions and function definitions. Everything included between "/*" and
  433. "*/" is considered a comment and will not be interpreted. Comments cannot
  434. be nested. The "/*" and "*/" are not recognized as comment delimiters
  435. inside string or character constants. Global variables are those variables
  436. that are known to all functions, unless their names are reused as local
  437. variables. Global variables can be initialized using any expression that
  438. involves either constants or other globals that are already defined at that
  439. point. Function definitions can appear in any order and their must be at
  440. least one function called "main" with no parameters. It is this function
  441. that is called when the script is started. Every function is supposed to
  442. return an integer value as result. Functions can be called recursively.
  443. There are many built-in functions that are already defined when the script
  444. is started.
  445.  
  446. This is an example of a simple script that displays the message "The number
  447. is 123" in the terminal window:
  448.  
  449.     int Number = 123;   /* This is a global variable */
  450.  
  451.     main ()     /* Every script must have a main() function */
  452.     {
  453.         /* display() is a built-in function */
  454.         display("The number is %i\r", Number);
  455.     }
  456.  
  457.  
  458. IDENTIFIERS
  459.  
  460. An identifier is a sequence of letters and digits; the first character must
  461. be a letter. The underscore "_" counts as a letter. An identifier can be of
  462. any length up to 255 characters. All characters are significant and are
  463. case sensitive. There are three types of identifiers: keywords, function
  464. names, variable names. The keywords are: "break", "char", "else", "for",
  465. "if", "int", "return", "while".
  466.  
  467.  
  468. CONSTANTS
  469.  
  470. An integer constant is a sequence of decimal digits, or 0x followed by up
  471. to 8 hexadecimal digits. An integer value is represented internally by 4
  472. bytes (32 bits). A minus sign before a constant is considered as an unary
  473. operator, not a part of the constant itself. A character constant is a
  474. sequence of 1 to 4 characters enclosed in single quotes. Character
  475. constants are converted to integer values, the byte values corresponding to
  476. the ASCII codes of the characters. A string constant is a sequence of
  477. characters enclosed in double quotes. String constants are automatically
  478. terminated by a NULL character. The value of a string constant is the
  479. address of the first character. Some examples of valid constants:
  480.  
  481.     1234567
  482.     0xABCD1234
  483.     'a'
  484.     'TEXT'
  485.     "An apple a day keeps troubles away"
  486.  
  487. In character and string constants the backslash "\" is used as an escape
  488. sequence according to the following table:
  489.  
  490.     LF      0x0A    \n
  491.     TAB     0x09    \t
  492.     FF      0x0C    \f
  493.     BELL    0x07    \a
  494.     BS      0x08    \b
  495.     CR      0x0D    \r
  496.     VT      0x0B    \v
  497.     NULL    0x00    \0
  498.     any     0x..    \x..    (2 hex digits)
  499.  
  500. If the character following a backslash is not one of those specified the
  501. backslash is ignored. This can be used to represent the backslash itself,
  502. to put a single quote into a character constant or to put a double quote
  503. into a string constant. Some examples;
  504.  
  505.     "Going to the next line...\r"
  506.     '\0'
  507.     "This is a single backslash: \\"
  508.     "\"Hello world!\""
  509.     '\''
  510.     '\x03'  /* That's a control-C */
  511.  
  512.  
  513. VARIABLES
  514.  
  515. There are four types of variables: characters, integers, pointers and
  516. arrays. Integers represent 32 bit signed values and characters 8 bit signed
  517. values. Pointers hold the 32 bit address of integers, characters or other
  518. pointers. Arrays are more or less equivalent to pointers. The following
  519. examples show how variables are defined:
  520.  
  521.     char c;     /* "c" is a character variable */
  522.     int n;      /* "n" is an integer variable */
  523.     char *ptr;  /* "ptr" is a pointer to characters */
  524.     char **hdl; /* "hdl" is a pointer to character pointers */
  525.     int *p;     /* "p" is a pointer to integers */
  526.     int **q;    /* "q" is a pointer to integer pointers */
  527.     char a[80]; /* "a" points to an array of 80 characters (80 bytes) */
  528.     int b[10];  /* "b" points to an array of 10 integers (40 bytes) */
  529.     char *c[5]; /* "c" points to an array of 5 character pointers (20 b) */
  530.     int *d[5];  /* "d" points to an array of 5 integer pointers (20 b) */
  531.  
  532. Variable declarations can be grouped together like this:
  533.  
  534.     char c, *ptr, **hdl, a[80], *c[5];
  535.     int n, *p, **q, b[10], *d[5];
  536.  
  537. Variables can be initialized using any legal expression, not only
  538. constants. Arrays can only be initialized at the global level, i.e. outside
  539. of function definitions. Initialized arrays must not include their size
  540. between the square brackets, the size is calculated based on the
  541. initializing values.
  542.  
  543.     char c = 'x';
  544.     int n = -123;
  545.     int m = n * 10;     /* "m" is set to -1230 */
  546.     char message[] = "This is a character string";
  547.     char *messages[] =  /* Array of strings */
  548.         { "This is string #1", "Another string", "and so on..." };
  549.     int a[] = { 1, 2, 3, 4, 5 };    /* Array of 5 integers */
  550.  
  551. The are no logical variables. Everything that is not zero is considered to
  552. be true.
  553.  
  554.  
  555. EXPRESSIONS
  556.  
  557. The following is a list of the supported operators that build up an
  558. expression. The list is by increasing precedence. Normally operators group
  559. left to right unless otherwise noted below. Note that the assignment is an
  560. operator, that an expression may contain several assignments, and that an
  561. assignment returns a value. Logical and numerical operators can be freely
  562. mixed, everything not zero is considered to be true. The precedence level
  563. can be changed by using parentheses. The boolean operators will return 1 as
  564. true.
  565.  
  566.     Assignment                      =                       (right to left)
  567.  
  568.     Logical or                      ||
  569.  
  570.     Logical and                     &&
  571.  
  572.     Equal, not equal                ==  !=
  573.  
  574.     Relational operators            <   <=  >   >=
  575.  
  576.     Add, subtract                   +   -
  577.  
  578.     Multiply, divide, modulo        *   /   %
  579.  
  580.     Logical not, increment,
  581.     decrement, unary minus,
  582.     indirection, address of         !   ++  --  -   *   &   (right to left)
  583.  
  584.     Function call, array element    ()  []
  585.  
  586. The increment or decrement operators can be used before or after a
  587. variable. If the operator comes before the variable (preincrement,
  588. predecrement) the variable is incremented, or decremented, and then the
  589. variable's value is used in the expression evaluation. If the operator
  590. comes after the variable (postincrement, postdecrement) the current value
  591. of the variable is used in the expression evaluation, and then the variable
  592. is incremented, or decremented.
  593.  
  594. Array subscripts start with 0. There is no runtime check of array
  595. boundaries. An array subscript can be any valid expression. Some examples:
  596.  
  597.     char a[80];
  598.     c = a[0];                       /* The first element */
  599.     c = a[79];                      /* The last element */
  600.     c = a[i = (79 - Func(x)*3)];    /* Expression as subscript */
  601.  
  602. For pointer arithmetic the following rules apply: if an integer value is
  603. added or subtracted from a pointer (a pointer is an address) then the
  604. integer value is first scaled depending on what the pointer is pointing to:
  605. 1 for characters, 4 for integers, 4 for pointers. If two pointers are
  606. subtracted the result is scaled in the same way and yields an integer value
  607. representing the number of objects separated by the two pointers. The two
  608. pointers must point to the same type of objects.
  609.  
  610. A function identifier without a parameter list in an expression results in
  611. the address of the function being used. If there is a parameter list, the
  612. function is called and the integer value returned by the function is used.
  613. Functions can also be called indirectly, using any expression that yields a
  614. valid function address followed by a parameter list. Some examples:
  615.  
  616.     int pf;         /* "int" can be used as function pointer */
  617.     int i;
  618.     pf = Func;      /* "pf" will contain address of function "Func" */
  619.     i = Func();     /* "i" gets function result */
  620.     i = (pf)();     /* "i" gets function result */
  621.  
  622.  
  623. FUNCTIONS
  624.  
  625. A function definition can only occur in the outer, global level. A function
  626. cannot be defined inside another function. All functions are supposed to
  627. return integers. A function definition consists of the function name,
  628. followed by a parameter definition list enclosed in parentheses, followed
  629. by a compound statement. The parameter definition list describes the
  630. function parameters. These parameters are considered as local variables
  631. inside the function. Example:
  632.  
  633.     /* The following function takes 3 parameters: a character, an integer
  634.     and a character pointer. It always returns the value 123. */
  635.  
  636.     Function (char c, int i, char *p)
  637.     {
  638.         /* ... */
  639.         return 123;
  640.     }
  641.  
  642. A function call consists of the function name followed by a parameter list.
  643. The parameter list is a comma separated list enclosed in parentheses of
  644. expressions. All parameters are passed by value. There is no verification
  645. if the number of parameters is correct or if the values passed to a
  646. function correspond to the types of the declared parameters. Example:
  647.  
  648.     i = Function ('x', 4567 + x, "Hello");
  649.  
  650.  
  651. STATEMENTS
  652.  
  653. A compound statement starts with an open brace "{" and terminates with a
  654. closing brace "}". There is an optional variable definition part followed
  655. by a list of statements. Variables defined inside a compound statement are
  656. local to that compound statement (block).
  657.  
  658. A statement can be:
  659.     compound statement
  660.     expression ;
  661.     if ( expression ) statement
  662.     if ( expression ) statement else statement
  663.     while ( expression ) statement
  664.     for ( opt expr1 ; opt expr2 ; opt expr3 ) statement
  665.     break ;
  666.     return ;
  667.     return expression ;
  668.     ;
  669.  
  670. The two forms of the conditional statement are:
  671.     if ( expression ) statement
  672.     if ( expression ) statement else statement
  673. In both cases the expression is evaluated and if it is nonzero, the first
  674. substatement is executed. In the second case the second substatement is
  675. executed if the expression is 0. The "else" ambiguity is resolved by
  676. connected an "else" with the last encountered "else"-less "if".
  677.  
  678. The "while" statement has the form:
  679.     while ( expression ) statement
  680. The substatement is executed repeatedly so long as the value of the
  681. expression remains nonzero. The test takes place before each execution of
  682. the statement.
  683.  
  684. The "for" statement has the form:
  685.     for ( opt expr1 ; opt expr2 ; opt expr3 ) statement
  686. This statement is equivalent to:
  687.     expression1 ;
  688.     while ( expression2 ) {
  689.         statement
  690.         expression3;
  691.     }
  692. Thus the first expression specifies initialization for the loop, the second
  693. specifies a test, made before each iteration, such that the loop is exited
  694. when the expression becomes 0; the third expression often specifies an
  695. incrementation which is performed after each iteration. Any or all of the
  696. expressions may be dropped. A missing expression2 makes the implied "while"
  697. clause equivalent to while(1); other missing expressions are simply dropped
  698. from the expansion above.
  699.  
  700. The statement
  701.     break ;
  702. causes termination of the smallest enclosing "while" or "for" statement;
  703. control passes to the statement following the terminating statement.
  704.  
  705. A function returns to its caller by means of the "return" statement, which
  706. has one of the forms:
  707.     return ;
  708.     return expression ;
  709. In the first case the returned value is undefined. In the second case the
  710. value of the expression is returned to the caller of the function. If
  711. required, the expression is converted to an integer. Flowing off the end of
  712. a function is equivalent to a return with no return value.
  713.  
  714. The null statement has the form
  715.     ;
  716. A null statement is useful to supply a null body to a looping statement
  717. such as "while". 
  718.  
  719.  
  720. ___________________________________________________________________________
  721. INTRINSIC FUNCTIONS
  722.  
  723.  
  724. Intrinsic functions are built-in and need not to be defined in the script.
  725. They can be called by any script.
  726.  
  727. All file access functions operate on the CIS-B up- and download folder,
  728. which is the folder that can be set with the "Binary file transfer
  729. options..." menu item. File names can be up to 31 characters long.
  730.  
  731. All formatting functions (display, format, type) use a template string to
  732. specify the formatting to be done on the following parameters. Format
  733. specifiers begin with the character % and include zero or more of the
  734. following conversion specification elements (optional fields are in
  735. brackets):
  736.     % [option flags] [field size] conversion
  737. Some of these elements are optional, but if present, they must be specified
  738. in the order in which they are described below.
  739. Option flags (optional):
  740.     -   Left adjust output in field, pad on right (default is to right
  741.         justify).
  742.     0   Use zero (0) rather than space for the pad character
  743. Field size specification (optional):
  744.     The minimum field width, expressed as a decimal integer. The
  745.     corresponding parameter will be printed in a field at least this wide.
  746. Conversion characters (required)
  747.     c   Parameter is a character
  748.     i   Parameter is an integer
  749.     s   Parameter is a null terminated string
  750.     %   Print a %, no parameter used
  751. The format specification elements must correspond to the following
  752. parameters. Some examples:
  753.     char k, m[80];
  754.     int n;
  755.     type("Unrecognized character %c on line %i of file %s\r", k, n, m);
  756.  
  757.  
  758. autolf          Set the auto linefeed flag on or off
  759.  
  760.     call:   autolf(flg)
  761.     flg:    zero means off, nonzero means on
  762.  
  763.  
  764. beep            Macintosh system beep
  765.  
  766.     call:   beep()
  767.  
  768.  
  769. catalog         Return file info
  770.  
  771.     call:   err = catalog(i,name,&type,&dsize,&rsize,&cdate,&mdate)
  772.     err:    Macintosh file system error, 0 if no error
  773.     i:      If 0, then name must be specified and information about the
  774.             file with that name is returned, if it exists.
  775.             If non-zero information (including file name) about the i-th
  776.             file in the folder is returned.
  777.     name:   Pointer to character string of at least 32 characters. This
  778.             is the file name (specified or returned depending on the value
  779.             of i).
  780.     type:   Integer (4 bytes). File type.
  781.     dsize:  Data fork size in bytes.
  782.     rsize:  Resource fork size in bytes.
  783.     cdate:  Creation date in seconds.
  784.     mdate:  Modification date in seconds.
  785.  
  786.  
  787. date            Convert seconds from Macintosh clock to date and time
  788.  
  789.     call:   date(sec, &yr, &mo, &da, &ho, &mi, &se, &dw)
  790.     sec:    seconds
  791.     yr:     year (1904..20xx)
  792.     mo:     month (1..12)
  793.     da:     day (1..31)
  794.     ho:     hour (0..23)
  795.     mi:     minutes (0..59)
  796.     se:     seconds (0..59)
  797.     dw:     day of week (1..7, Sunday is 1)
  798.  
  799.  
  800. display         Display in the terminal window
  801.  
  802.     call:   display(templ, ...)
  803.     templ:  template string
  804.     ...:    variable number of arguments (maximum 9)
  805.  
  806.  
  807. download        Download (receive) a binary file using X-Modem protocol
  808.  
  809.     call:   err = download(name, bin)
  810.     err:    error code returned.
  811.             0 if Ok. 1 if timeout. 2 if cancel. 3 if abort (2 consecutive
  812.             control-X characters received). All other values are Macintosh
  813.             file system errors.
  814.     name:   File name for new file
  815.     bin:    non-zero to recognize and use MacBinary format
  816.  
  817.  
  818. format          Formatted conversion of values into a string
  819.  
  820.     call:   format(str, templ, ...)
  821.     str:    string for result
  822.     templ:  template string
  823.     ...:    variable number of arguments (maximum 8)
  824.  
  825.  
  826. free            Dispose of the memory allocated by the new() function
  827.  
  828.     call:   free(p)
  829.     p:      pointer returned by previous call to new() function
  830.  
  831.  
  832.  
  833. getcts          Get current state of CTS input line
  834.                 (*** not yet implemented ***)
  835.  
  836.     call:   onoff = getcts()
  837.     onoff:  0 if negated, 1 if asserted
  838.  
  839.  
  840. lecho           Set the local echo flag on or off
  841.  
  842.     call:   lecho(flg)
  843.     flg:    zero means off, non-zero means on
  844.  
  845.  
  846. move            Move bytes from source to destination
  847.  
  848.     call:   move(src, dest, cnt)
  849.     src:    source character pointer
  850.     dest:   destination character pointer
  851.     cnt:    number of bytes to move
  852.  
  853.  
  854. new             Allocate memory
  855.  
  856.     call:   p = new(size)
  857.     p:      pointer to memory, or 0 if not enough memory available
  858.     size:   number of bytes to allocate
  859.  
  860.  
  861. nextline        Wait for the next line received over the serial input port
  862.  
  863.     call:   err = nextline(line, t)
  864.     err:    0 line received, 1 timeout, 2 cancel, 3 abort (2 consecutive
  865.             control-X characters received)
  866.     line:   string to hold line
  867.     t:      timeout value in ticks (1/60th of second)
  868.  
  869.  
  870. pause           Pause for specified amount of time
  871.  
  872.     call:   err = pause(t)
  873.     err:    1 timeout, 2 cancel.
  874.     t:      timeout value in ticks (1/60th of second)
  875.  
  876.  
  877. prompt          Wait for a prompt string to come over the serial input port
  878.  
  879.     call:   err = prompt(str, t)
  880.     err:    0 string received, 1 timeout, 2 cancel, 3 abort (2 consecutive
  881.             control-X characters received).
  882.     str:    string to wait for (case sensitive)
  883.     t:      timeout value in ticks (1/60th of second)
  884.  
  885.  
  886. recho           Set the remote echo flag on or off
  887.  
  888.     call:   recho(flg)
  889.     flg:    zero means off, non-zero means on
  890.  
  891.  
  892. save            Set the save & display flag on or off
  893.  
  894.     call:   save(flg)
  895.     flg:    zero means off, non-zero means on
  896.  
  897.  
  898. send            Send a text file over the serial output port
  899.  
  900.     call:   err = send(name)
  901.     err:    error code returned.
  902.             0 if Ok. 2 if cancel. 3 abort (2 consecutive control-X
  903.             characters received). All other values are Macintosh file
  904.             system errors.
  905.     name:   File name
  906.  
  907.  
  908. setdtr          Set DTR output line
  909.  
  910.     call:   setdtr(onoff)
  911.     onoff:  0 to negate, 1 to assert
  912.  
  913.  
  914. setup           Serial communications port setup
  915.  
  916.     call:   err = setup(baud, data, parity, stop, port, dtr)
  917.     err:    0 if no error
  918.     baud:   0=300, 1=600, 2=1200, 3=2400, 4=4800, 5=9600, 6=19200, 7=38400,
  919.             8=57600 baud (or -1 for no change)
  920.     data:   0=7, 1=8 data bits (or -1 for no change)
  921.     parity: 0=no, 1=even, 2=odd parity (or -1 for no change)
  922.     stop:   0=1, 1=2 stop bit (or -1 for no change)
  923.     port:   0=modem, 1=printer port (or -1 for no change)
  924.     dtr:    1=don't drop DTR when quitting (or -1 for no change)
  925.  
  926.  
  927. stack           Return free memory available for script heap and stack
  928.  
  929.     call:   bytes = stack()
  930.     bytes:  Combined free heap and stack space
  931.  
  932.  
  933. strcmp          Compare two strings (not case sensitive)
  934.  
  935.     call:   res = strcmp(str1, str2)
  936.     str1:   first string
  937.     str2:   second string
  938.     res:    0 if strings are equal, positive if str1 > str2, negative if
  939.             str1 < str2
  940.  
  941.  
  942. terminal        Set terminal parameters
  943.  
  944.     call:   terminal(lecho, recho, autolf, save)
  945.     lecho:  Local echo flag (or -1 if no modification)
  946.     recho:  Remote echo flag (or -1 if no modification)
  947.     autolf: Auto line feed flag (or -1 if no modification)
  948.     save:   Save & capture flag (or -1 if no modification)
  949.  
  950.  
  951. time            Return seconds from Macintosh clock
  952.  
  953.     call:   sec = time()
  954.  
  955.  
  956. type            Send a string over the serial output port
  957.  
  958.     call:   type(templ, ...)
  959.     templ:  template string
  960.     ...:    variable number of arguments (maximum 9)
  961.  
  962.  
  963. upload          Upload (transmit) a binary file using X-Modem protocol
  964.  
  965.     call:   err = upload(name, bin)
  966.     err:    error code returned.
  967.             0 if Ok. 1 if timeout. 2 if cancel. 3 abort (2 consecutive
  968.             control-X characters received). All other values are Macintosh
  969.             file system errors.
  970.     name:   File name
  971.     bin:    non-zero to recognize and use MacBinary format
  972.  
  973.  
  974. ___________________________________________________________________________
  975. THE CONFIGURATION RESOURCE
  976.  
  977.  
  978. Some program parameters are kept in a configuration resource in the
  979. "Terminal" application. These parameters cannot be changed while the
  980. program is running, so there is no corresponding dialog in the "Options"
  981. menu. You must use "ResEdit" to change those parameters. The resource name
  982. is "CNFG" and the id is 128.
  983.  
  984. Offset Length Description
  985.   0       2    Font number (must be a monospaced font, e.g. Monaco is 4)
  986.   2       2    Font size (e.g. 12)
  987.   4       2    Lines in terminal window (e.g. 25)
  988.   6       2    Columns in terminal window (e.g. 80)
  989.   8       4    Size of terminal buffer in bytes (e.g. 32768)
  990.  12       4    Size of serial input buffer in bytes (e.g. 4096)
  991.  16       4    Size of serial output buffer in bytes (e.g. 256)
  992.  20       4    Size of script memory in bytes (e.g. 16384)
  993.  
  994. In "ResEdit" this may look like this:
  995.  
  996. 000000    0004 000C 0019 0050
  997. 000008    0000 8000 0000 1000
  998. 000010    0000 0100 0000 4000
  999.  
  1000. On a Macintosh Plus Monaco 9 with 24 lines of 80 columns fills the entire
  1001. screen, but on a Macintosh IIcx with an Apple color monitor Monaco 12 with
  1002. 25 lines of 80 columns fills the entire screen.
  1003.  
  1004. Note that if the buffer sizes are changed the "SIZE" resource must be
  1005. changed accordingly under MultiFinder, otherwise the program may not get
  1006. enough memory. Yoy can use the "About..." menu item to check for available
  1007. memory while "Terminal" is running.
  1008.  
  1009.  
  1010. ___________________________________________________________________________
  1011. COMMENTS AND SUGGESTIONS
  1012.  
  1013.  
  1014. Send any comments, bug reports and suggestions to my address:
  1015.     Erny Tontlinger
  1016.     33, route d'Arlon
  1017.     L-8410 Steinfort
  1018.     Luxembourg
  1019. or via electronic mail to my CompuServe account 73720,2200.
  1020. I'am a radio amateur, so you can reach me also via the packet radio network
  1021. at LX1YZ @ LX0PAC.
  1022.  
  1023. This program is absolutely free, including the C sources. So do with it
  1024. what you like, but please include the documentation if you give it away.
  1025.